{* $Id$ *}
{include_core file="admin/lib/header.html" title="掌柜订单列表"}
<style type="text/css">
  .list-table tbody tr td .btn{
      font-size: 14px;
  }
</style>
  <div class="page-header border-bottom clearfix">
    <h2 class="left">{if $status == 0}回收{/if}掌柜订单管理<span>在这里对{if $status == 0}回收{/if}掌柜订单进行管理</span></h2>
    {if $status == 1}
      {* <a href="{AnUrl('order/admin/store_order?status=0')}" class="btn btn-success btn-sm right"><i class="icon-add"></i>回收站</a> *}
    {else}
    <a href="{AnUrl('order/admin/store_order?status=1')}" class="btn btn-default btn-sm right">&lt; 返回掌柜订单列表</a>
    {/if}
    {if user_config::ADMIN == $role_id}
      <a  style="margin-top:5px; display:block; float:right;" data-url="{get_url()}&is_excel=1"  class="btn btn-xs btn-success js_downList export_excel">导出EXCEL</a>
    {/if}
  </div>
  <div class="search-form js_advancedForm">
    <form action="{AnUrl('order/admin/store_order')}" method="get" class="js_orderSearchForm">
      <input type="hidden" name="status" value="{URLTracker::val('status')}">
      <p>
        <label for="" class="search-f-label">订单编号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[order_code]" value="{URLTracker::val('search_filter', 'order_code')}">
      </p>
      <p>
        <label for="" class="search-f-label">合伙人姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[agency_realname]" value="{URLTracker::val('search_filter', 'agency_realname')}">
      </p>
      <p>
        <label for="" class="search-f-label">合伙人手机号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[agency_user_name]" value="{URLTracker::val('search_filter', 'agency_user_name')}">
      </p>
      <p>
        <label for="" class="search-f-label">掌柜手机：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[store_user_name]" value="{URLTracker::val('search_filter', 'store_user_name')}">
      </p>
      <p class="js-time-range-check">
        <label for="" class="search-f-label">下单时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-start-time" name="search_filter[start_date_add]" value="{URLTracker::val('search_filter', 'start_date_add')}">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-end-time" name="search_filter[end_date_add]" value="{URLTracker::val('search_filter', 'end_date_add')}">
      </p>
      <p class="js-time-range-check">
        <label for="" class="search-f-label">收货时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-start-time" name="search_filter[start_date_receiver]" value="{URLTracker::val('search_filter', 'start_date_receiver')}">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-end-time" name="search_filter[end_date_receiver]" value="{URLTracker::val('search_filter', 'end_date_receiver')}">
      </p>
      <p class="js-time-range-check">
        <label for="" class="search-f-label">支付时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-start-time" name="search_filter[start_date_pay]" value="{URLTracker::val('search_filter', 'start_date_pay')}">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2 js-date-picker js-end-time" name="search_filter[end_date_pay]" value="{URLTracker::val('search_filter', 'end_date_pay')}">
      </p>
      <p>
        <label for="" class="search-f-label"></label>
        <button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button>
      </p>
    </form>
  </div>
  <!--start:列表-->
    <div class="list-table-filters">
        <p>
            <span class="label label-info">按状态</span>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("progress", "-1")}")}' {if URLTracker::val("progress") == -1 && URLTracker::val("status") == 1 } class="label label-primary" {else} class="label label-default" {/if}>全部</a>
            {foreach order_config::$store_progress as $k => $v}
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("progress", $k)}")}' {if URLTracker::val("progress") == $k && URLTracker::val("status") == 1} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
            {/foreach}
        </p>
        <p>
            <span class="label label-info">按类型</span>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("store_type", "-1")}")}' {if URLTracker::val("store_type") == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
            {foreach store_config::$type_arr as $k => $v}
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("store_type", $k)}")}' {if URLTracker::val("store_type") == $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
            {/foreach}
        </p>
        <p>
            <span class="label label-info">送货单</span>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("delivery_note_status", -1)}")}' {if URLTracker::val("delivery_note_status") === -1} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("delivery_note_status", -2)}")}' {if URLTracker::val("delivery_note_status") === -2} class="label label-primary" {else} class="label label-default" {/if}>含送货单</a>
            {foreach order_config::$delivery_status as $k => $v}
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("delivery_note_status", $k)}")}' {if URLTracker::val("delivery_note_status") === $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
            {/foreach}
        </p>
        <p>
          <span class="label label-info">按兑换</span>
          <a href='{AnUrl("order/admin/store_order?{URLTracker::set("exchange_type", "")}")}' {if URLTracker::val('exchange_type') == ''} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
          <a href='{AnUrl("order/admin/store_order?{URLTracker::set("exchange_type", "all")}")}' {if  URLTracker::val('exchange_type') == 'all'} class="label label-primary" {else} class="label label-default" {/if}>含兑换</a>
          <a href='{AnUrl("order/admin/store_order?{URLTracker::set("exchange_type", "bbcoin")}")}' {if  URLTracker::val('exchange_type') == 'bbcoin'} class="label label-primary" {else} class="label label-default" {/if}>抱抱币兑换</a>
        </p>
        <p>
            <span class="label label-info">其　他</span>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("service_dealer", 0)}")}' {if URLTracker::val('service_dealer') == 0} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
            <a href='{AnUrl("order/admin/store_order?{URLTracker::set("service_dealer", 1)}")}' {if URLTracker::val('service_dealer') == 1} class="label label-primary" {else} class="label label-default" {/if}>只看委派</a>
        </p>
    </div>
{include_core file="admin/lib/pager.html"}
  <table class="list-table goods-table">
    {$order_type_list = order_config::$order_type}
    <thead>
      <tr>
        <th style="min-width:100px;">订单编号</th>
        <th style="width:1em">&nbsp;</th>
        <th style="min-width:200px;">商品</th>
        <th style="width:30px;">单价(元)</th>
        <th style="width:30px;">数量</th>
        <th style="width:30px;">单项总价(元)</th>
        <th style="width:30px;">总量</th>
        <th style="min-width:100px;text-align:right">价格汇总(元)</th>
        <th style="min-width:150px;">掌柜信息</th>
        <th style="width:50px;">状态 &amp; 操作</th>
      </tr>
    </thead>
    <tbody>
      {foreach $order_list as $k => $v}
        <tr><td colspan="11" class="hr">&nbsp;</td></tr>
        {if $v.order_relation_count}
          {foreach $v.order_relation as $key=>$order_relation_info}
            <tr data-id="{$v.id}" id="dataList{$v.id}">
              {if $key == 0}
                <td rowspan="{$v.order_relation_count + $v.order_exchange_relation_count}">
                  {if $v.is_ious == 1}<span class="label label-success">白</span>{/if}
                  {if $v.pay_user_money > 0}<span class="label label-info">余</span>{/if}
                  {if $v.exchange_num > 0}<span class="label label-warning">兑</span>{/if}
                  {if $v.original_agency_id > 0}<span class="label label-danger">派</span>{/if}
                  {if $v.is_ious || $v.pay_user_money > 0 || $v.exchange_num > 0 || $v.original_agency_id > 0}<br />{/if}
                  订单号：<br />
                  {order_helper::order_id_encode($v.id)}<br />
                  下单时间：<br />{$v.add_time}<br />
                  {if $v.task_user_id}代理下单：{user_helper::display_name($v.task_user_id)}<br />{/if}
                  {if $v.task_desc}代理备注：{$v.task_desc}<br />{/if}
                  {if $v.transaction_id}
                  交易号:<br />{$v.transaction_id}
                  {/if}
                </td>
              {/if}
              {if $key == 0}
                <td class="abs-center" style="color:#bbbbbb;font-size:14px;font-weight:bold;background-color:#f8f8f8;" rowspan="{$v.order_relation_count}"> 现 付</td>
              {/if}
              {$goods_info = goods_helper::get_goods_info($order_relation_info['goods_id'])}
              <td>
                  <span class="label label-default">{$goods_info['title']}</span><br/>
                  分类：{_uri('category', $goods_info['category_id'], 'title')}<br/>
                  商品简介：<br/><p class="">{$goods_info['intro']}</p>
              </td>
              <td><span class="label label-default">{num_keep_two_round($order_relation_info.goods_price)}</span></td>
              <td>{$order_relation_info.goods_num}</td>
              <td><span class="label label-default">{num_keep_two_round($order_relation_info.real_price)}</span></td>
              {if $key == 0}
                <td rowspan="{$v.order_relation_count + $v.order_exchange_relation_count}">{$v.goods_num + $v.exchange_num}</td>
                <td rowspan="{$v.order_relation_count}" style="text-align:right;">
                    <p>
                        <span class="label label-default">总价 {num_keep_two_round($v.price)}</span><br />
                        {if $v.pay_user_money > 0}
                        <span class="label label-warning">余额支付 {num_keep_two_round($v.pay_user_money)}</span><br />
                        {/if}
                        <span class="hr"></span>
                        <span class="label label-info">需付 {num_keep_two_round($v.price - $v.pay_user_money)}</span><br />
                    </p>
                    {if $v.is_ious}
                    <p>&nbsp;</p>
                    <p>合伙人 {$v.dealer_info.realname}</p>
                    <p>
                        <span class="label label-{if $v.order_delivery_note.is_return_cash}success">已{else}default">将{/if}返本金 {num_keep_two_round($v.order_delivery_note.return_cash)}</span><br />
                        <span class="label label-{if $v.order_delivery_note.is_return_bbcoin}success">已{else}default">将{/if}返抱币 {intval($v.order_delivery_note.return_bbcoin)}</span><br />
                    </p>
                    {/if}
                </td>
                <td rowspan="{$v.order_relation_count + $v.order_exchange_relation_count}">
                  {if $v.pay_time != '0000-00-00 00:00:00'}
                    <p>支付时间：{$v.pay_time}</p>
                    <p>&nbsp;</p>
                  {/if}
                  {if $v.dealer_info}
                    <fieldset>
                        <legend>合伙人{if $v.original_agency_id}<em>(委派)</em>{/if}</legend>
                        {$v.dealer_info.realname}({$v.dealer_info.mobile})
                    </fieldset>
                  {/if}
                  {if $v.store_user_role == user_config::STORE_MANAGER || $v.store_user_role == user_config::STORE_OWNER}
                    <fieldset>
                        <legend>门店信息</legend>
                        店铺: {$v.store_info.title}{if $v.store_info.title_branch} &middot; {$v.store_info.title_branch}{/if}<br/>
                        掌柜: {$v.store_user_info.realname}({$v.store_user_info.mobile})<br/>
                        <br/>
                        店铺地址：<br/>
                        省：{$province_info = area_helper::get_area_info($v.store_info.province_id)}{$province_info['area']}<br/>
                        市：{$city_info = area_helper::get_area_info($v.store_info.city_id)}{$city_info['area']}<br/>
                        区：{$county_info = area_helper::get_area_info($v.store_info.district_id)}{$county_info['area']}<br/>
                        <br/>
                        详细地址: <br/>{$v.store_info.address}
                    </fieldset>
                  {/if}
                  <fieldset>
                    <legend>收货人</legend>
                    {$v.store_user_info.realname}({$v.store_user_info.mobile})
                  </fieldset>
                </td>
                {$order_progress_list = order_config::$store_progress}
                <td rowspan="{$v.order_relation_count + $v.order_exchange_relation_count}">
                  {if $v.progress == 1}
                    <span class="label label-warning">{$order_progress_list[$v.progress]}</span>
                  {elseif $v.progress == 10}
                    <span class="label label-success">{$order_progress_list[$v.progress]}</span>
                  {elseif $v.progress == 15}
                    <span class="label label-default">{$order_progress_list[$v.progress]}</span>
                  {else}
                    <span class="label label-info">{$order_progress_list[$v.progress]}</span>
                  {/if}
                  <!-- 送货单状态 -->
                  {$delivery_status = $v.order_delivery_note.status}
                  {if isset($delivery_status)}
                    <span{if $delivery_status != 0} style="display:none"{/if} class="label label-default js-delivery-status js-delivery-status-0">{order_config::$delivery_status[0]}</span>
                    <span{if $delivery_status != 1} style="display:none"{/if} class="label label-warning js-delivery-status js-delivery-status-1">{order_config::$delivery_status[1]}</span>
                    <span{if $delivery_status != 2} style="display:none"{/if} class="label label-info js-delivery-status js-delivery-status-2">{order_config::$delivery_status[2]}</span>
                    <span{if $delivery_status != 3} style="display:none"{/if} class="label label-danger js-delivery-status js-delivery-status-3">{order_config::$delivery_status[3]}</span>
                    <span{if $delivery_status != 4} style="display:none"{/if} class="label label-success js-delivery-status js-delivery-status-4">{order_config::$delivery_status[4]}</span>
                    <span{if $delivery_status != 5} style="display:none"{/if} class="label label-warning js-delivery-status js-delivery-status-5">{order_config::$delivery_status[5]}</span>
                  {/if}
                  <!-- /送货单状态 -->
                  <!-- 发票状态 -->
                  {if $v.make_invoice_status == 1}
                    <span class="label label-success">已开发票</span>
                  {/if}
                  <!-- /发票状态 -->
                  <span class="hr"></span>
                  {if $role_id == user_config::ADMIN || $role_id == user_config::OPERATOR}
                    {if $status}
                      <a href="{AnUrl("order/admin/delete?id={$v.id}")}" class="btn btn-danger btn-xs js_deleteOrder"><i class="icon-trash icon-white"></i>删除订单</a>
                    {else}
                      <a href="{AnUrl("order/admin/change_status?id={$v.id}")}" class="btn btn-warning btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>还原</a>
                    {/if}
                  {/if}
                  {if $role_id == user_config::ADMIN || $role_id == user_config::OPERATOR || $role_id == user_config::ASSISTANT}
                    {if $v.progress == 5}
                      <a href="{AnUrl("order/admin/store_order/finish_store_order?id={$v.id}")}" class="btn btn-danger btn-xs js_finishStoreOrder"><i class="icon-trash icon-white"></i>确认送达</a>
                    {/if}
                  {/if}
                  {if $v.progress == 1 && $v.assigned_id == 0}
                    <!-- 服务合伙人派单 -->
                    {if $v.original_agency_id > 0}
                      <a data-order_id="{$v.id}" data-agency_id="{$v.agency_id}" data-original_agency_id="{$v.original_agency_id}" href="{AnUrl("order/admin/store_order/ajax_get_service_dealers_list")}" class="btn btn-success btn-xs js-set-service-agency"><i class="icon-trash icon-white"></i>委派变更</a>
                    {else}
                      <a data-order_id="{$v.id}" data-agency_id="{$v.agency_id}" href="{AnUrl("order/admin/store_order/ajax_get_service_dealers_list")}" class="btn btn-info btn-xs js-set-service-agency"><i class="icon-trash icon-white"></i>委派订单</a>
                    {/if}
                    <!-- /服务合伙人派单 -->
                  {/if}
                  {if in_array($role_id, array(user_config::ADMIN, user_config::MULTIPLE_DIVISION, user_config::FINANCIAL_MANAGEMENT))}
                    <!-- 送货单操作 -->
                    <a{if $delivery_status != 1} style="display:none"{/if} data-id="{$v.id}" data-status="1" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-info btn-xs js-delivery-note-btn js-delivery-note-preview-btn"><i class="icon-trash icon-white"></i>送货单预审</a>
                    <a{if $delivery_status != 5} style="display:none"{/if} data-id="{$v.id}" data-status="5" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-info btn-xs js-delivery-note-btn js-delivery-note-verify-btn"><i class="icon-trash icon-white"></i>送货单审核</a>
                    <a{if $delivery_status != 2} style="display:none"{/if} data-id="{$v.id}" data-status="2" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-success btn-xs js-delivery-note-btn js-delivery-note-payback-btn"><i class="icon-trash icon-white"></i>确认回款</a>
                    <!-- /送货单操作 -->
                  {/if}
                </td>
              {/if}
            </tr>
          {/foreach}
        {/if}
      {if $v.order_exchange_relation_count}
          {foreach $v.order_exchange_relation as $key => $order_exchange_relation_info}
          {$goods_info = goods_helper::get_goods_info($order_exchange_relation_info['goods_id'])}
          <tr style="background-color:#fffeec">
              {if $key == 0}
              <td class="abs-center" style="color:#b7ab40;font-size:14px;font-weight:bold;background-color:#fffdbf;" rowspan="{$v.order_exchange_relation_count}"> 兑 换</td>
              {/if}
              <td style="overflow:hidden;">
                  <span class="label label-warning">{$goods_info['title']}</span><br/>
                  分类：{_uri('category', $goods_info['category_id'], 'title')}<br/>
                  商品简介：<br/><p class="">{$goods_info['intro']}</p>
              </td>
              <td><span class="label label-warning">{intval($order_exchange_relation_info.goods_price)} 币</span></td>
              <td>{$order_exchange_relation_info.goods_num}</td>
              <td><span class="label label-warning">{intval($order_exchange_relation_info.real_price)} 币</span></td>
              {if $key == 0}
              <td rowspan="{$v.order_exchange_relation_count}" style="text-align:right;">
                  <span class="label label-warning">抱币总计 {intval($v.pay_bbcoin)}</span>
              </td>
              {/if}
          </tr>
          {/foreach}
      {/if}
      {foreachelse}
        <tr><td class="txtleft" colspan="10">暂无数据</td></tr>
      {/foreach}
    </tbody>
  </table>
{include_core file="admin/lib/pager.html"}
<!--end:列表-->
<div class="float-bg" style="z-index: 19999; display: none"></div>
{include_core file="module/order_cancel.html"}
{include_core file="module/order_delete.html"}
{include_core file="module/order_confirm_money.html"}
{include_core file="module/order_finish_store.html"}
{include_core file="module/order_recommend.html"}
{include_core file="module/order_delivery_verify.html"}
{include_core file="module/search_form_check.html"}
{include_core file="module/send_order_to_service_agency.html"}
{include_core file="module/order_export.html"}
{include_core file="admin/lib/footer.html"}
